package com.qf.topic;

import com.qf.util.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

/**
 * topic类型
 */
public class Publisher {

    @Test
    public void publish() throws Exception {
        //1. c
        Connection connection = ConnectionUtil.getConnection();

        //2. c
        Channel channel = connection.openChannel().get();

        //3. 构建topic交换机绑定
        channel.exchangeDeclare("topic_exchange", BuiltinExchangeType.TOPIC);
        channel.queueBind("topic_queue1","topic_exchange","*.orange.*");
        channel.queueBind("topic_queue2","topic_exchange","*.*.big");
        channel.queueBind("topic_queue2","topic_exchange","lazy.#");

        //4. p
        channel.basicPublish("topic_exchange","lazy.orange.dog",null,"懒橘狗！".getBytes());
        channel.basicPublish("topic_exchange","big.big.big",null,"大大大！".getBytes());
        channel.basicPublish("topic_exchange","lazy.xxx.yyy.zzz.sd.asf.sdfsd.fds.f.sdfs.ddf.sdf.dsfds.fds.df",null,"阿巴阿巴！".getBytes());

        //5. c
        channel.close();
        connection.close();
    }
}
